<?php
namespace App\Libs\FBAInventoryServiceMWS;
use App\Libs\FBAInventoryServiceMWS\Model\ListInventorySupplyByNextTokenRequest;
use App\Libs\FBAInventoryServiceMWS\Model\ListInventorySupplyRequest;
class InventoryMws
{
    private static $_instance = null;

    private $_fields = ['SellerId',
                        'MWSAuthToken',
                        'Marketplace',
                        'MarketplaceId',
                        'SellerSkus',
                        'QueryStartDateTime',
                        'ResponseGroup',
                        'NextToken'];

    public static function getInit(){
        if(!is_object(self::$_instance)){
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    /**
     * 返回卖家库存状况信息。
     * API ListInventorySupply
     * @param array $con
     * @return array
     */
    public function listInventorySupply($con = array())
    {
        $request = $this->_getRequest(new ListInventorySupplyRequest(),$con);
        if (!($request instanceof ListInventorySupplyRequest)) {
            $request = new ListInventorySupplyRequest($request);
        }
        $parameters = $request->toQueryParameterArray();
        $parameters['Action'] = 'ListInventorySupply';
        return $parameters;
    }

    /**
     * 返回下一页卖家库存状况信息。
     * API ListInventorySupplyByNextToken
     * @param array $con
     * @return array
     */
    public function listInventorySupplyByNextToken($con = array())
    {
        $request = $this->_getRequest(new ListInventorySupplyByNextTokenRequest(),$con);
        if (!$request instanceof ListInventorySupplyByNextTokenRequest) {
            $request = new ListInventorySupplyByNextTokenRequest($request);
        }
        $parameters = $request->toQueryParameterArray();
        $parameters['Action'] = 'ListInventorySupplyByNextToken';
        return $parameters;
    }

    private function _getRequest($request,$con = array()) {
        foreach($con as $k=>$v){
            if($k&&in_array($k,$this->_fields)){
                $setter = "set$k";
                $request->$setter($v);
            }
        }
        return $request;
    }
}
